const xuanze = require('../db/xuanze.js');
if (typeof require !== 'undefined') XLSX = require('xlsx');

var workbook = XLSX.readFile('../data/test.xlsx');
var worksheet = workbook.Sheets['Sheet1']

for (var i = 1; i <= 10; i++) {
    var cp_qes = 'A' + i;
    var cp_ans1 = 'B' + i;
    var cp_ans2 = 'C' + i;
    var cp_ans3 = 'D' + i;
    var cp_ans4 = 'E' + i;
    var cl_qes = worksheet[cp_qes];
    var cl_ans1 = worksheet[cp_ans1];
    var cl_ans2 = worksheet[cp_ans2];
    var cl_ans3 = worksheet[cp_ans3];
    var cl_ans4 = worksheet[cp_ans4];
    var val_qes = (cl_qes ? cl_qes.v : undefined);
    var val_ans1 = (cl_ans1 ? cl_ans1.v : undefined);
    var val_ans2 = (cl_ans2 ? cl_ans2.v : undefined);
    var val_ans3 = (cl_ans3 ? cl_ans3.v : undefined);
    var val_ans4 = (cl_ans4 ? cl_ans4.v : undefined);
    var newXz = new xuanze({
        Cno: 'CS',
        Tno: i,
        Qes: val_qes,
        Ans1: val_ans1,
        Ans2: val_ans2,
        Ans3: val_ans3,
        Ans4: val_ans4,
    });
    newXz.save(function(err){
        if(err){
            console.log(err);
            return;
        }
        console.log("success");
    });
}
xuanze.find({},function(err,data){
    if(err){
        console.log(err);
        return;
    }
    console.log(data);
})

